package com.framework.common.util;

import com.thoughtworks.xstream.XStream;

/**
 * @author zhoubb
 * @version V1.0
 * @Date 2020/5/23 16:48
 * @since JDK 1.8
 */
public class MessageUtil {
    /**
     * 返回消息类型：文本
     */
    public static final String RESP_MESSAGE_TYPE_TEXT = "text";

    /**
     * 返回消息类型：音乐
     */
    public static final String RESP_MESSAGE_TYPE_MUSIC = "music";

    /**
     * 返回消息类型：图文
     */
    public static final String RESP_MESSAGE_TYPE_NEWS = "news";

    /**
     * 请求消息类型：文本
     */
    public static final String REQ_MESSAGE_TYPE_TEXT = "text";

    /**
     * 请求消息类型：图片
     */
    public static final String REQ_MESSAGE_TYPE_IMAGE = "image";

    /**
     * 请求消息类型：链接
     */
    public static final String REQ_MESSAGE_TYPE_LINK = "link";

    /**
     * 请求消息类型：地理位置
     */
    public static final String REQ_MESSAGE_TYPE_LOCATION = "LOCATION";

    /**
     * 请求消息类型：音频
     */
    public static final String REQ_MESSAGE_TYPE_VOICE = "voice";

    /**
     * 请求消息类型：视频
     */
    public static final String REQ_MESSAGE_TYPE_VIDEO = "video";

    /**
     * 请求消息类型：推送
     */
    public static final String REQ_MESSAGE_TYPE_EVENT = "event";

    /**
     * 事件类型：subscribe(订阅)
     */
    public static final String EVENT_TYPE_SUBSCRIBE = "subscribe";

    /**
     * 事件类型：unsubscribe(取消订阅)
     */
    public static final String EVENT_TYPE_UNSUBSCRIBE = "unsubscribe";

    /**
     * 事件类型：CLICK(自定义菜单点击事件)
     */
    public static final String EVENT_TYPE_CLICK = "CLICK";

    /**
     * 文本消息对象转换成xml
     *
     * @param textMessage
     *            文本消息对象
     * @return xml
     */
    public static String textMessageToXml(Object textMessage) {
        XStream xstream = new XStream();
        xstream.alias("xml", textMessage.getClass());
        return xstream.toXML(textMessage);
    }

//    // 图文消息转化为XML
//    public static String newsMessageToXml(Object newsMessage) {
//        XStream xstream = new XStream();
//        xstream.alias("xml", newsMessage.getClass());
//        xstream.alias("item", new News().getClass());
//        return xstream.toXML(newsMessage);
//    }

    public static void main(String[] args) {
//        VoiceMessage voiceMessage=new VoiceMessage();
//        voiceMessage.setToUserName("aaaa");
//        voiceMessage.setFromUserName("bbbb");
//        voiceMessage.setCreateTime(new Date().getTime());
//        voiceMessage.setMsgType("voice");
//        Voice voice=new Voice();
//        voice.setMediaId("llllllllllllllllll");
//        voiceMessage.setVoice(voice);
//        String textMessageToXml = textMessageToXml(voiceMessage);
//        System.out.println(textMessageToXml);
    }
}
